package com.itcast.controller;

import com.itcast.domain.Account;
import com.itcast.service.AccoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccoutController {

    @Autowired
    private AccoutService accoutService;


    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model){

        List<Account> list = accoutService.findAll();
        model.addAttribute("list",list);
        System.out.println("表现出：查询了所有账户");
        return "success";
    }


    /**
     * 保存
     * @param account
     * @return
     */
    @RequestMapping("/add")
    public String save(Account account){
        System.out.println("表现层：保存了账户");
        accoutService.saveAccount(account);
        return "redirect:/account/findAll";
    }
}
